package arena.base;

import gameframework.base.MoveStrategy;
import gameframework.base.SpeedVector;
import gameframework.base.SpeedVectorDefaultImpl;

import java.awt.Point;

import arena.soldier.ArmedUnitSoldier;
import arena.soldier.Soldier;

public class SquadStrategyMovement  implements MoveStrategy {
	Soldier hero;
	Point currentGoal;
	Point currentPosition;
	ArmedUnitSoldier wolf;
	
	public SquadStrategyMovement(Soldier hero, ArmedUnitSoldier p) {
		this.hero = hero;
		this.wolf = p;
	}

	public SpeedVector getSpeedVector() {
		reachNewGoal();
		double dist = currentPosition.distance(currentGoal);
		int xDirection = (int) Math.rint((currentGoal.getX() - currentPosition.getX())
				/ dist);
		int yDirection = (int) Math.rint((currentGoal.getY() - currentPosition.getY())
				/ dist);
		SpeedVector move = new SpeedVectorDefaultImpl(new Point(xDirection,
				yDirection));
		
		return move;
	}
	
	public void reachNewGoal() {
		currentGoal = hero.getPosition();
		currentPosition = wolf.getPosition();
	}
	
	public void setPosition(Point p) {
		currentPosition = p;
	}
}